package com.iqcctt.simpleflow.typeengine;

import com.iqcctt.simpleflow.exception.SimpleFlowException;
import com.iqcctt.simpleflow.typeengine.example.DateTypeExample;
import com.iqcctt.simpleflow.typeengine.example.IntegerTypeExample;
import com.iqcctt.simpleflow.typeengine.example.StringTypeExample;
import java.util.HashMap;
import java.util.Map;

public class TypeFactory {
    private static Map<Object, TypeInterface> registry = new HashMap<>();

    static {
        registry.put("java.lang.String",new StringTypeExample());
        registry.put("int",new IntegerTypeExample());
        registry.put("java.lang.Integer",new IntegerTypeExample());
        registry.put("Integer",new IntegerTypeExample());
        registry.put("java.util.Date",new DateTypeExample());
    }

    public static TypeInterface getInvokeStrategy(String key) throws Exception {
        try{
            TypeInterface typeInterface = registry.get(key);
            if(typeInterface==null){
                throw new SimpleFlowException("key值为空:"+key);
            }
            return typeInterface;
        }catch (Exception e){
            throw new SimpleFlowException("key值为空:"+key);
        }
    }
}
